package gson.gson.Interface;

import com.google.gson.FieldNamingStrategy;

import java.lang.reflect.Field;

/*
User{userName='Alice', age=30, password='123'}
Serialized JSON with custom field naming strategy: {"_username":"Alice","_age":30,"_password":"123"}
 */
public class CustomFieldNamingStrategy implements FieldNamingStrategy {
    // translateName 方法：将字段名称转换为小写，并添加前缀 "_"
    @Override
    public String translateName(Field f) {
        return "_" + f.getName().toLowerCase();
    }
}
